home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / centiped.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  5KB  |  213 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13.  
  14. static int flipscreen;
  15.  
  16. static struct rectangle spritevisiblearea =
  17. {
  18.     1*8, 31*8-1,
  19.     0*8, 30*8-1
  20. };
  21.  
  22.  
  23.  
  24. /***************************************************************************
  25.  
  26.   Centipede doesn't have a color PROM. Eight RAM locations control
  27.   the color of characters and sprites. The meanings of the four bits are
  28.   (all bits are inverted):
  29.  
  30.   bit 3 alternate
  31.         blue
  32.         green
  33.   bit 0 red
  34.  
  35.   The alternate bit affects blue and green, not red. The way I weighted its
  36.   effect might not be perfectly accurate, but is reasonably close.
  37.  
  38. ***************************************************************************/
  39. static void setcolor(int pen,int data)
  40. {
  41.     int r,g,b;
  42.  
  43.  
  44.     r = 0xff * ((~data >> 0) & 1);
  45.     g = 0xff * ((~data >> 1) & 1);
  46.     b = 0xff * ((~data >> 2) & 1);
  47.  
  48.     if (~data & 0x08) /* alternate = 1 */
  49.     {
  50.         /* when blue component is not 0, decrease it. When blue component is 0, */
  51.         /* decrease green component. */
  52.         if (b) b = 0xc0;
  53.         else if (g) g = 0xc0;
  54.     }
  55.  
  56.     palette_change_color(pen,r,g,b);
  57. }
  58.  
  59. WRITE_HANDLER( centiped_paletteram_w )
  60. {
  61.     paletteram[offset] = data;
  62.  
  63.     /* the char palette will be effectively updated by the next interrupt handler */
  64.  
  65.     if (offset >= 12 && offset < 16)    /* sprites palette */
  66.     {
  67.         int start = Machine->drv->gfxdecodeinfo[1].color_codes_start;
  68.  
  69.         setcolor(start + (offset - 12),data);
  70.     }
  71. }
  72.  
  73. static int powerup_counter;
  74.  
  75. void centiped_init_machine(void)
  76. {
  77.     powerup_counter = 10;
  78. }
  79.  
  80. int centiped_interrupt(void)
  81. {
  82.     int offset;
  83.     int slice = 3 - cpu_getiloops();
  84.     int start = Machine->drv->gfxdecodeinfo[0].color_codes_start;
  85.  
  86.  
  87.     /* set the palette for the previous screen slice to properly support */
  88.     /* midframe palette changes in test mode */
  89.     for (offset = 4;offset < 8;offset++)
  90.         setcolor(4 * slice + start + (offset - 4),paletteram[offset]);
  91.  
  92.     /* Centipede doesn't like to receive interrupts just after a reset. */
  93.     /* The only workaround I've found is to wait a little before starting */
  94.     /* to generate them. */
  95.     if (powerup_counter == 0)
  96.         return interrupt();
  97.     else
  98.     {
  99.         powerup_counter--;
  100.         return ignore_interrupt();
  101.     }
  102. }
  103.  
  104.  
  105.  
  106. WRITE_HANDLER( centiped_vh_flipscreen_w )
  107. {
  108.     if (flipscreen != (data & 0x80))
  109.     {
  110.         flipscreen = data & 0x80;
  111.         memset(dirtybuffer,1,videoram_size);
  112.     }
  113. }
  114.  
  115.  
  116.  
  117. /***************************************************************************
  118.  
  119.   Draw the game screen in the given osd_bitmap.
  120.   Do NOT call osd_update_display() from this function, it will be called by
  121.   the main emulation engine.
  122.  
  123. ***************************************************************************/
  124. void centiped_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  125. {
  126.     int offs;
  127.  
  128.     if (palette_recalc() || full_refresh)
  129.         memset (dirtybuffer, 1, videoram_size);
  130.  
  131.     for (offs = videoram_size - 1;offs >= 0;offs--)
  132.     {
  133.         if (dirtybuffer[offs])
  134.         {
  135.             int sx,sy;
  136.  
  137.  
  138.             dirtybuffer[offs] = 0;
  139.  
  140.             sx = offs % 32;
  141.             sy = offs / 32;
  142.  
  143.             drawgfx(bitmap,Machine->gfx[0],
  144.                     (videoram[offs] & 0x3f) + 0x40,
  145.                     (sy + 1) / 8,    /* support midframe palette changes in test mode */
  146.                     flipscreen,flipscreen,
  147.                     8*sx,8*sy,
  148.                     &Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  149.         }
  150.     }
  151.  
  152.     /* Draw the sprites */
  153.     for (offs = 0;offs < 0x10;offs++)
  154.     {
  155.         int spritenum,color;
  156.         int flipx;
  157.         int x, y;
  158.         int sx, sy;
  159.  
  160.  
  161.         spritenum = spriteram[offs] & 0x3f;
  162.         if (spritenum & 1) spritenum = spritenum / 2 + 64;
  163.         else spritenum = spritenum / 2;
  164.  
  165.         flipx = (spriteram[offs] & 0x80) ^ flipscreen;
  166.         x = spriteram[offs + 0x20];
  167.         y = 240 - spriteram[offs + 0x10];
  168.  
  169.         /* Centipede is unusual because the sprite color code specifies the */
  170.         /* colors to use one by one, instead of a combination code. */
  171.         /* bit 5-4 = color to use for pen 11 */
  172.         /* bit 3-2 = color to use for pen 10 */
  173.         /* bit 1-0 = color to use for pen 01 */
  174.         /* pen 00 is transparent */
  175.         color = spriteram[offs+0x30];
  176.         Machine->gfx[1]->colortable[3] =
  177.                 Machine->pens[Machine->drv->gfxdecodeinfo[1].color_codes_start + ((color >> 4) & 3)];
  178.         Machine->gfx[1]->colortable[2] =
  179.                 Machine->pens[Machine->drv->gfxdecodeinfo[1].color_codes_start + ((color >> 2) & 3)];
  180.         Machine->gfx[1]->colortable[1] =
  181.                 Machine->pens[Machine->drv->gfxdecodeinfo[1].color_codes_start + ((color >> 0) & 3)];
  182.  
  183.         drawgfx(bitmap,Machine->gfx[1],
  184.                 spritenum,0,
  185.                 flipscreen,flipx,
  186.                 x,y,
  187.                 &spritevisiblearea,TRANSPARENCY_PEN,0);
  188.  
  189.         /* mark tiles underneath as dirty */
  190.         sx = x >> 3;
  191.         sy = y >> 3;
  192.  
  193.         {
  194.             int max_x = 1;
  195.             int max_y = 2;
  196.             int x2, y2;
  197.  
  198.             if (x & 0x07) max_x ++;
  199.             if (y & 0x0f) max_y ++;
  200.  
  201.             for (y2 = sy; y2 < sy + max_y; y2 ++)
  202.             {
  203.                 for (x2 = sx; x2 < sx + max_x; x2 ++)
  204.                 {
  205.                     if ((x2 < 32) && (y2 < 30) && (x2 >= 0) && (y2 >= 0))
  206.                         dirtybuffer[x2 + 32*y2] = 1;
  207.                 }
  208.             }
  209.         }
  210.  
  211.     }
  212. }
  213.